package com.wxxymakers.grademark.controller;

import com.wxxymakers.grademark.model.entity.WxRole;
import com.wxxymakers.grademark.model.mapper.WxRoleMapper;
import com.wxxymakers.grademark.utils.RestResponse;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @AUTHOR soft
 * @DATE 2018/12/26 17:49
 * @DESCRIBE 角色控制器
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private WxRoleMapper roleMapper;

    @RequiresRoles({"admin"})
    @PostMapping("/list")
    public RestResponse list() {
        List<WxRole> wxRoles = roleMapper.selectList(null);
        if (!CollectionUtils.isEmpty(wxRoles)) {
            return RestResponse.ok(wxRoles);
        }
        return RestResponse.fail();
    }
}
